//
//  CycleBaseCollectionView.m
//  CycleBaseControl
//
//  Created by ddy on 2018/8/14.
//  Copyright © 2018年 cycle. All rights reserved.
//

#import "CycleBaseCollectionView.h"

@implementation CycleBaseCollectionView

-(void)awakeFromNib{
    [super awakeFromNib];
    [self cycle_initCollectionViewSource];
}
-(instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout{
    if(self = [super initWithFrame:frame collectionViewLayout:layout]){
        [self cycle_initCollectionViewSource];
    }
    return self;
}
/**
 *  初始化基本信息
 */
- (void)cycle_initCollectionViewSource{
    
    if (@available(iOS 11.0,*)) {
        //        self.estimatedRowHeight             = 0;
        //        self.estimatedSectionFooterHeight   = 0;
        //        self.estimatedSectionHeaderHeight   = 0;
        ///contentInsetAdjustmentBehavior属性也是用来取代automaticallyAdjustsScrollViewInsets属性的，推荐使用这种方式。
        if ([self respondsToSelector:@selector(setContentInsetAdjustmentBehavior:)]) {
            self.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }
    }
    
}
/**
 * 快速创建一个collectionView含1个cell注册
 */
+ (CycleBaseCollectionView *)cycle_createCollectionViewWithFrame:(CGRect)rect bgColor:(UIColor *)bgColor layout:(UICollectionViewLayout *)layout delegate:(id)delegate dataSource:(id)dataSource isNib:(BOOL)isNib cell:(UICollectionViewCell *)cell identifier:(NSString *)identifier{

    CycleBaseCollectionView *collectionView = [[CycleBaseCollectionView alloc]initWithFrame:rect collectionViewLayout:layout];
    collectionView.delegate       = delegate;
    collectionView.dataSource     = dataSource;
    collectionView.showsVerticalScrollIndicator   = NO;
    collectionView.showsHorizontalScrollIndicator = NO;
    collectionView.backgroundColor = bgColor;
    //注册Cell
    if (isNib) {
        [collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([cell class]) bundle:nil] forCellWithReuseIdentifier:identifier];
    } else {
        [collectionView registerClass:[cell class] forCellWithReuseIdentifier:identifier];
    }
    return collectionView;
}

@end
